#include "Sin.h"
#include "Cos.cpp"
long double Sin::calcul(long double aux1)
{
    return sinl(aux1);
}

long double Sin::calcul()
{
    if (!fStang)
        exit(1);
    return calcul(fStang->calcul());
}

char *Sin::derivare()
{
    char *aux1, *aux2, *aux, *aux00;

    if (!fStang)
        exit(1);

    aux1 = fStang->derivare();
    aux2 = fStang->toString();

    aux00 = Cos::concatTermeni(aux2);
    aux = Inmultit::concatTermeni(aux00, aux1);
    delete aux1; delete aux2; delete aux00;

    return aux;
}

long double Sin::calculDerivata()
{
    if (!fStang)
        exit(1);

    return Inmultit::calcul(Cos::calcul(fStang->calcul()), fStang->calculDerivata());
}

char *Sin::toString()
{
    char *aux, *aux1;
    int nrP;

    if (!fStang)
        exit(1);
    aux1 = fStang->toString();

    aux = concatTermeni(aux1);
    delete aux1;
    return aux;
}

char *Sin::concatTermeni(char *aux1)
{
    char *aux;
    int nrP;

    nrP = aux1[0] == '(' ? 0 : 2;
    aux = new char[strlen(aux1) + 4 + nrP];

    strcpy(aux, "sin");
    if (nrP) strcat(aux, "(");
    strcat(aux, aux1);
    if (nrP) strcat(aux, ")");

    return aux;
}
